# https://vip.1905.com/huayilist/t_18/p1o2.shtml
# 1905VIP影院
import os
import re
import shutil

import requests

from util.headers import get_headers_init_user_agent

root = 'static/1905VIP影院/'
if os.path.exists(root):
    shutil.rmtree(root)
os.makedirs(root)

url = 'https://vip.1905.com/huayilist/t_18/p1o2.shtml'
response = requests.get(url)
# print(response.status_code)
content = response.content.decode('utf-8')
# print(content)
# items = re.findall(r'<a class="img" href="//vip.1905.com/huayi/play/(.*?).shtml" target="_blank" title="(.*?)" bind="postHover" data-id="430549" data-type="1"><img src="//static.m1905.cn/images/vip/cnc/lazyImg.gif" data-lazysrc="//image11.m1905.cn/uploadfile/(.*?).jpg" class="lazyImg" width="220" height="318" alt="神话"><span class="mask"></span><b class="icons playIcon"></b></a>', content)
items = re.findall(r'<img src="//static.m1905.cn/images/vip/cnc/lazyImg.gif" data-lazysrc="//image11.m1905.cn/uploadfile/(.*?).jpg" class="lazyImg" width="220" height="318" alt="(.*?)">', content,re.S)
# print(items)
for item in items:
    # print(item)
    title = item[1]
    thumb_url = f'https://image11.m1905.cn/uploadfile/{item[0]}.jpg'
    headers = get_headers_init_user_agent()
    headers.update({
        'referer': url
    })
    thumb_response = requests.get(thumb_url, headers=headers)
    with open(f"{root}/{title}_thumb.jpg", "wb") as f:
        f.write(thumb_response.content)